package com.eschool.beans;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import com.eschool.model.Course;
import com.eschool.model.Room;
import com.eschool.service.SchoolManagementService;
import com.eschool.service.impl.SchoolManagementServiceImpl;

@ManagedBean(name="courseBean")
@ViewScoped
public class CourseBean {
	
	Course course = new Course();

	SchoolManagementService service = new SchoolManagementServiceImpl();
		
	public Course getCourse() {
		return course;
	}
	public void setCourse(Course course) {
		this.course = course;
	}
	
	public String performAction()
	{
		String message;
		
		if(service.addCourse(course)) {
			message = "Course Succesfully Added";
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Success Message", message));
		}
		else {
			message = "Course Not Added";
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error Message", message));
		}
		
		return "AddCourse";
	}

}
